package com.dmai.capacity.platform.oauth.common.service.impl;

import com.dmai.capacity.platform.common.model.GatewayLog;
import com.dmai.capacity.platform.oauth.common.mapper.GatewayLogDao;
import com.dmai.capacity.platform.oauth.common.service.IGatewayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


@Service
public class GatewayLogServiceImpl implements IGatewayLogService {

    @Autowired
    private GatewayLogDao gatewayLogDao;


    /**
     * 添加
     *
     * @param gatewayLog
     */
    @Override
    public int save(GatewayLog gatewayLog) {
        return gatewayLogDao.save(gatewayLog);
    }

    @Override
    public GatewayLog get(String traceId) {
        return gatewayLogDao.findById(traceId);
    }


    @Override
    @Transactional
    public int handleResponse(String traceId, Integer responseCode, String responseData) {
        int handleResult = -1;

        if (responseCode != null && 0 == responseCode) {
            handleResult = 1;
        }
        return gatewayLogDao.update(traceId, new Date(), HttpStatus.OK.value(), responseData, null, handleResult);
    }

}
